#ifndef __WSA_INIT_H__
#define __WSA_INIT_H__

#include "header_sock.h"

/**
 * @brief WSA初始化类
 * 全局唯一静态变量，生命周期与主程序同步
 * !当前头文件不允许重复导入，否则编译报错
 */
struct WsaInit {
	// 禁止拷贝构造和赋值
	WsaInit(const WsaInit &)            = delete;
	WsaInit &operator=(const WsaInit &) = delete;

	// 移动构造和赋值
	WsaInit(WsaInit &&)            = delete;
	WsaInit &operator=(WsaInit &&) = delete;

	// 构造函数
	WsaInit() {
#if defined(_WIN32) || defined(_WIN64)
		SetConsoleOutputCP(CP_UTF8);
		WSADATA wsaData;
		if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
			std::cerr << "WSAStartup failed..." << std::endl;
			return 1;
		}
#endif
	};

	// 析构函数
	~WsaInit() {
#ifdef _WIN32
		WSACleanup();
#endif
	};
} WsaInit;
#endif // __WSA_INIT_H__
